<?php
/**
 * 数据参数模型
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-05 13:37:27
 * @version $Id$
 */

class DataMenuConfigModel extends BaseModel {

	  protected $_table = 'content';
    protected $_primary = 'contentid';

    /**
     * 返回给终端的可执行sql语句的字段名称数组
     * @var [type]
     */
    public $_field_arr = ['mokuai_id','mokuai_name','mokuai_order','mokuai_icon','enable','is_html5','html5_url'];

    function dataMenuForPosition($mokuai_id_arr, $mokuai_id_arrAll, $department_position)
    {
      	$query = DB::select(implode(",", $this->_field_arr))->from('data_menu_config')
      	->where('`enable`', '=', 1)->and_where('yiyuan_id', '=', $this->yiyuan_id);

      	if ($mokuai_id_arr) {
      		$query->where_open();
      		$query->and_where('mokuai_id', 'in', $mokuai_id_arr);
      	}

      	if ($mokuai_id_arrAll) {
      		if ($mokuai_id_arr)
      			$query->or_where('mokuai_id', 'not in', $mokuai_id_arrAll);
      		else
      			$query->and_where('mokuai_id', 'not in', $mokuai_id_arrAll);
      		$query->where_close();
      	}

      	if ($department_position == '护士长') {
      		$query->and_where('ishushizhang', '=', 1);
      	}
      	if ($department_position == '护士') {
      		$query->and_where('ishushi', '=', 1);
      	}
	    return $query->execute()->as_array();
    }

    /**
     * 获取所有菜单
     * @param  integer $yiyuan_id [description]
     * @return [type]             [description]
     */
    public function allDataMenu($yiyuan_id = 0)
    {
    	return DB::select(implode(",", $this->_field_arr))
                ->from('data_menu_config')
                ->where('`yiyuan_id`', '=', $yiyuan_id)
                ->where('`enable`', '=', 1)
                ->execute()
                ->as_array();
    }
}
